package cn.iocoder.yudao.module.fengdong.smartelderly.dal.mysql.billing;

import java.util.*;

import cn.iocoder.yudao.framework.common.pojo.PageResult;
import cn.iocoder.yudao.framework.mybatis.core.query.LambdaQueryWrapperX;
import cn.iocoder.yudao.framework.mybatis.core.mapper.BaseMapperX;
import cn.iocoder.yudao.module.fengdong.smartelderly.dal.dataobject.billing.BillingDO;
import org.apache.ibatis.annotations.Mapper;
import cn.iocoder.yudao.module.fengdong.smartelderly.controller.admin.billing.vo.*;
import org.apache.ibatis.annotations.Param;

/**
 * 收费记录 Mapper
 *
 * @author 沣东养老院管理员
 */
@Mapper
public interface BillingMapper extends BaseMapperX<BillingDO> {

    default PageResult<BillingDO> selectPage(BillingPageReqVO reqVO) {
        return selectPage(reqVO, new LambdaQueryWrapperX<BillingDO>()
                .eqIfPresent(BillingDO::getType, reqVO.getType())
                .eqIfPresent(BillingDO::getTitle, reqVO.getTitle())
                .eqIfPresent(BillingDO::getOldmanId, reqVO.getOldmanId())
                .likeIfPresent(BillingDO::getOldmanName, reqVO.getOldmanName())
                .eqIfPresent(BillingDO::getOldmanCard, reqVO.getOldmanCard())
                .eqIfPresent(BillingDO::getMoney, reqVO.getMoney())
                .eqIfPresent(BillingDO::getState, reqVO.getState())
                .betweenIfPresent(BillingDO::getStartTime, reqVO.getStartTime())
                .betweenIfPresent(BillingDO::getEndTime, reqVO.getEndTime())
                .eqIfPresent(BillingDO::getPayTime, reqVO.getPayTime())
                .eqIfPresent(BillingDO::getContent, reqVO.getContent())
                .betweenIfPresent(BillingDO::getCreateTime, reqVO.getCreateTime())
                .orderByDesc(BillingDO::getId));
    }

    default List<BillingDO> selectList(BillingExportReqVO reqVO) {
        return selectList(new LambdaQueryWrapperX<BillingDO>()
                .eqIfPresent(BillingDO::getType, reqVO.getType())
                .eqIfPresent(BillingDO::getTitle, reqVO.getTitle())
                .eqIfPresent(BillingDO::getOldmanId, reqVO.getOldmanId())
                .likeIfPresent(BillingDO::getOldmanName, reqVO.getOldmanName())
                .eqIfPresent(BillingDO::getMoney, reqVO.getMoney())
                .eqIfPresent(BillingDO::getOldmanCard, reqVO.getOldmanCard())
                .eqIfPresent(BillingDO::getState, reqVO.getState())
                .betweenIfPresent(BillingDO::getStartTime, reqVO.getStartTime())
                .betweenIfPresent(BillingDO::getEndTime, reqVO.getEndTime())
                .eqIfPresent(BillingDO::getPayTime, reqVO.getPayTime())
                .eqIfPresent(BillingDO::getContent, reqVO.getContent())
                .betweenIfPresent(BillingDO::getCreateTime, reqVO.getCreateTime())
                .orderByDesc(BillingDO::getId));
    }

    /**
     *  查询今年该月份生成缴费单数量(oldmanId 不为空则查询该“长者”的缴费单数量)
     * @param billingReqVO
     */
    Long selectBillingExist(@Param("param") BillingCreateReqVO billingReqVO);
}
